// pages/information/information.js
var util = require('../../utils/util');
var App = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        date: '',//传入时间
        date_month: '',//显示时间
        store_name: ['全部', '工作提醒', '开单提醒', '跟进提醒'],
        type:0,
        page: 1,
        limit: 10,
        list:[],
    },
    
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var This = this;
        var time = util.formatTime(new Date());
        var date_value = time.slice(0, 4) + "-" + time.slice(5, 7)
        var date_value_month = time.slice(0, 4) + "-" + time.slice(5, 7)
        console.log(date_value)
        This.setData({
            date: date_value,
            date_month: date_value_month,
        })
        This.loading();
    },
    bindDateChange: function (e) {
        var This = this;
        This.setData({
            information_list: []
        })
        var date_month = e.detail.value
        var year = date_month.slice(0, 4)
        var month = date_month.slice(5, 7)
        var date_time = year + '-' + month
        This.setData({
            date_month: date_time,
            date: e.detail.value,
            list: [],
            page:1
        })
        This.loading();
    },
    loading(){
        var This = this;
        App._get('coach/Callerdetail/get_describe',{
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            date_str: This.data.date_month,
            type:This.data.type,
            page: This.data.page,
            limit: This.data.limit
        },function(res){
            if (res.status == 1) {
                if(res.data.length > 0){
                    for(var index in res.data) {
                        This.data.list.push(res.data[index]);
                    }
                    This.setData({
                        list: This.data.list
                    })
                }else{
                    // wx.showToast({
                    //     title: '加载到底部',
                    // })
                    This.setData({
                        list: This.data.list
                    })
                }
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    bindPickerChange(e){
        var This = this;
        This.setData({
            type:e.detail.value,
            list: [],
            page: 1
        })
        This.loading();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        var This = this;
        var pasges = This.data.page;
        pasges = pasges + 1;
        This.setData({
            page: pasges
        })
        setTimeout(function () {
            This.loading();
        }, 1000)
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})